#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,k,x,cnt,now,flg[N],ans=2e9;
struct node{
	int val,id;
}a[N<<2];
inline bool cmp(node p,node q){
	return p.val<q.val;
}
signed main(){
	freopen("contest.in","r",stdin);
	freopen("contest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k;
		for(int j=1;j<=k;j++){
			cin>>x;
			a[++cnt]={x,i};
		}
	}
	sort(a+1,a+cnt+1,cmp);
	int t=0;
	for(int i=1;i<=cnt;i++){
		while(t<=cnt&&now<n){
			t++;
			if(t<=cnt){
				flg[a[t].id]++;
				if(flg[a[t].id]==1) now++;
			}
		}
		if(t<=cnt) ans=min(ans,a[t].val-a[i].val);
		flg[a[i].id]--;
		if(flg[a[i].id]==0) now--;
	}
	cout<<ans;
	return 0;
}